/*
Simple Forum Auto Poster.
Copyright (C) 2011 Gianni Van Hoecke.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package gui.forums;

import domain.DomainController;
import domain.forumdata.Forum;
import java.util.Arrays;
import javax.swing.DefaultListModel;

/**
 *
 * @author Gianni Van Hoecke <gianni.vh@gmail.com>
 */
public class ForumsPanel extends javax.swing.JPanel {

    private DefaultListModel model;
    
    /** Creates new form ForumsPanel */
    public ForumsPanel() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        scrollPane = new javax.swing.JScrollPane();
        lstForumList = new javax.swing.JList();
        forumListActionPanel1 = new gui.forums.ForumListActionPanel();
        lblForumSelectInfo = new javax.swing.JLabel();

        setLayout(new java.awt.BorderLayout());

        lstForumList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        scrollPane.setViewportView(lstForumList);

        add(scrollPane, java.awt.BorderLayout.CENTER);
        add(forumListActionPanel1, java.awt.BorderLayout.PAGE_END);

        lblForumSelectInfo.setText("<html>Select the forums you want to post to:</html>");
        add(lblForumSelectInfo, java.awt.BorderLayout.PAGE_START);
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private gui.forums.ForumListActionPanel forumListActionPanel1;
    private javax.swing.JLabel lblForumSelectInfo;
    private javax.swing.JList lstForumList;
    private javax.swing.JScrollPane scrollPane;
    // End of variables declaration//GEN-END:variables

    public void loadForums()
    {
        this.model = new DefaultListModel();

        for(Forum forum : DomainController.getInstance().getForums().getForums())
        {
            this.model.addElement(forum.getForumName());
        }

        this.lstForumList.setModel(model);

        this.forumListActionPanel1.checkButtons();
    }

    public String[] getSelectedForums()
    {
        return Arrays.copyOf(this.lstForumList.getSelectedValues(), this.lstForumList.getSelectedValues().length, String[].class);
    }

    public void setButtonsEnabled(boolean enabled)
    {
        this.lstForumList.setEnabled(enabled);
        this.forumListActionPanel1.setButtonsEnabled(enabled);
    }
}